<template>
  <!-- 学员管理 -->
  <div class="mod-sys__params">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item>
        <el-select v-model="state.dataForm.historyFlag" placeholder="历史学员">
          <el-option label="否" :value="0" />
          <el-option label="是" :value="1" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="state.getDataList()">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="danger" @click="state.deleteHandle()">删除</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="studentEnrollHandle()">学员报名</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="headUrl" label="头像" header-align="center" align="center">
        <template v-slot="scope">
          <el-image style="height: 50px" :src="scope.row.headUrl" :preview-src-list="[scope.row.headUrl]" fit="fit" hide-on-click-modal preview-teleported />
        </template>
      </el-table-column>
      <el-table-column prop="realName" label="姓名" header-align="center" align="center"></el-table-column>
      <el-table-column prop="userTag" label="标签" header-align="center" align="center"></el-table-column>
      <el-table-column prop="gender" label="性别" header-align="center" align="center">
        <template v-slot="scope">
          <span>{{scope.row.gender == 0?'男':scope.row.gender == 1?'女':'保密'}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="age" label="年龄" header-align="center" align="center"></el-table-column>
      <el-table-column prop="mobile" label="手机号" header-align="center" align="center"></el-table-column>
      <el-table-column prop="province" label="省份" header-align="center" align="center"></el-table-column>
      <el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button type="primary" link @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="primary" link @click="state.deleteHandle(scope.row.id)">删除</el-button>
          <el-button type="primary" link @click="seePurchaseHandle(scope.row.id)">购买课程</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit" :total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="state.pageSizeChangeHandle" @current-change="state.pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update ref="addOrUpdateRef" @refreshDataList="state.getDataList"></add-or-update>

    <!-- 学员报名弹窗  -->
    <student-enroll ref="studentEnrollRef" @refreshDataList="state.getDataList"></student-enroll>

    <!-- 学员购买的课程详情 -->
    <student-purchase-course ref="studentPurchaseCourseRef"></student-purchase-course>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import { reactive, ref, toRefs } from "vue";
import AddOrUpdate from "./student-add-or-update.vue";
import studentEnroll from "./student-enroll.vue";
import studentPurchaseCourse from "./student-purchase-course.vue";

const view = reactive({
  getDataListURL: "/lingyao/student/page",
  getDataListIsPage: true,
  deleteURL: "/lingyao/student",
  deleteIsBatch: true,
  dataForm: {
    historyFlag: 0
  }
});

const state = reactive({ ...useView(view), ...toRefs(view) });

const addOrUpdateRef = ref();
const addOrUpdateHandle = (id?: number) => {
  addOrUpdateRef.value.init(id);
};

// 学员报名
const studentEnrollRef = ref();
const studentEnrollHandle = () => {
  studentEnrollRef.value.init();
};

// 查询购买的课程信息
const studentPurchaseCourseRef = ref();
const seePurchaseHandle = (id: number) => {
  studentPurchaseCourseRef.value.init(id);
};
</script>
